package com.whq.knowverywell.task;

import android.content.Context;
import android.os.AsyncTask;

import com.whq.knowverywell.business.http.GetOneStoreProductSalesDataUtil;
import com.whq.knowverywell.business.http.model.ProductSalesReturn;
import com.whq.knowverywell.util.LogUtil;
import com.whq.knowverywell.util.constant.CfgConstant;
import com.whq.knowverywell.util.constant.ModelConstant;

/**
 * 店柜明细获取数据
 * @author david
 *
 */
public class SummaryDetailTask extends AsyncTask<String, String, ProductSalesReturn> {
    private final static String TAG = SummaryDetailTask.class.getSimpleName();

    private Context context = null;
    private DetailResultDataListener listener;
    private int durationType;
    private String productNo;
    
    public SummaryDetailTask(Context context, DetailResultDataListener listener, int durationType, String productNo) {
        this.context = context;
        this.listener = listener;
        this.durationType = durationType;
        this.productNo = productNo;
    }
    
    @Override
    protected ProductSalesReturn doInBackground(String... params) {
        if (this.context == null) {
        	return null;
        }
        
        String orderBy = params[0];
        int pageNo = Integer.parseInt(params[1]);
        LogUtil.i(TAG, "orderBy[" + orderBy + "] pageNo[" + pageNo + "]");
        
        ProductSalesReturn huizongResult = null;
        switch (durationType) {
		case ModelConstant.DURATION_TYPE_YESTERDAY:
			huizongResult = GetOneStoreProductSalesDataUtil.getYesterdayDataList(this.context, productNo, orderBy, pageNo, CfgConstant.PAGE_COUNT);
			break;
		case ModelConstant.DURATION_TYPE_TODAY:
			huizongResult = GetOneStoreProductSalesDataUtil.getTodayDataList(this.context, productNo, orderBy, pageNo, CfgConstant.PAGE_COUNT);
			break;
		case ModelConstant.DURATION_TYPE_MONTH:
			huizongResult = GetOneStoreProductSalesDataUtil.getCurrentMonthDataList(this.context, productNo, orderBy, pageNo, CfgConstant.PAGE_COUNT);
			break;
		case ModelConstant.DURATION_TYPE_YEAR:
			huizongResult = GetOneStoreProductSalesDataUtil.getCurrentYearDataList(this.context, productNo, orderBy, pageNo, CfgConstant.PAGE_COUNT);
			break;
		default:
			break;
		}
        
        return huizongResult;
    }
    
    @Override
    protected void onPostExecute(ProductSalesReturn huizongResult) {
    	this.listener.handleDetailData(huizongResult);
    }
    
    public interface DetailResultDataListener {
    	public void handleDetailData(ProductSalesReturn huizongResult);
    }
}
